﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package ZLocalization {

    public class LocalizerXML extends Localizer {

        public function LocalizerXML(_arg1:XML){
            var _local3:XML;
            var _local4:Object;
            var _local5:int;
            var _local6:String;
            var _local7:XML;
            super(_arg1);
            this.m_raw = {};
            this.m_cached = {};
            var _local2:int;
            while (_local2 < _arg1.pkg.length()) {
                _local3 = _arg1.pkg[_local2];
                _local4 = {};
                _local5 = 0;
                while (_local5 < _local3.string.length()) {
                    _local7 = _local3.string[_local5];
                    _local4[_local7.@key.toString()] = _local7;
                    _local5++;
                };
                _local6 = _local3.@name.toString();
                this.m_raw[_local6] = _local4;
                this.m_cached[_local6] = {};
                _local2++;
            };
            this.m_locale = _arg1.@locale.toString();
            this.setSubstituter();
        }
        protected function parseStringNode(_arg1:XML):LocalizedString{
            var _local6:XML;
            var _local2:String = _arg1.original.toString();
            var _local3:Object = {};
            var _local4:int;
            while (_local4 < _arg1.variation.length()) {
                _local6 = _arg1.variation[_local4];
                _local3[_local6.@index.toString()] = _local6.toString();
                _local4++;
            };
            var _local5:LocalizedString = new LocalizedString(_local2, _local3);
            if (_arg1.@gender.toString() != ""){
                _local5.gender = _arg1.@gender.toString();
            };
            return (_local5);
        }
        override public function getString(_arg1:String, _arg2:String):LocalizedString{
            if (!this.m_raw.hasOwnProperty(_arg1)){
                return (null);
            };
            if (!this.m_cached[_arg1].hasOwnProperty(_arg2)){
                if (this.m_raw[_arg1].hasOwnProperty(_arg2)){
                    this.m_cached[_arg1][_arg2] = this.parseStringNode(this.m_raw[_arg1][_arg2]);
                } else {
                    return (null);
                };
            };
            return (this.m_cached[_arg1][_arg2]);
        }

    }
}//package ZLocalization 
